gas = [1, 2, 3, 4, 5], cost = [3, 4, 5, 1, 2]
//gas = [5, 1, 2, 3, 4], cost = [4, 4, 1, 5, 1]
gas = [5, 8, 2, 8], cost = [6, 5, 6, 6]
gas = [2], cost = [2]
var canCompleteCircuit = function (gas, cost) {
    let len = gas.length
    let price = []
    for (let i = 0; i < len; i++) {
        price[i] = gas[i] - cost[i]
    }
    console.log(price);
    let num = 0
    let index
    let flag = true
    let i = 0
    while (i < len) {
        num += price[i]
        if (num < 0) {
            num = 0
            i++
        } else {
            i++
        }
    }
    if (num >= 0) {
        return index
    } else {
        return -1
    }
};
console.log(canCompleteCircuit(gas, cost));
